import django_tables2 as tables
from seom.models import Person

class PersonTable(tables.Table):
    selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
    #first_name = tables.Column()
    #ln = tables.Column(accessor='last_name')
    fullname=tables.Column(order_by=("first_name", "last_name"))
    region_name=tables.Column(accessor="region.name")
    checked = tables.BooleanColumn()
    
    def __init__(self, *args, **kwargs):
        super(PersonTable, self).__init__(*args, **kwargs)
    
    def render_fullname(self, value):
        return '%s' % value.upper()
    
    def render_checked(self, value):
        if region_name=='Moscow':
            value=True
        else:
            value=False

    class Meta:
        model = Person
        # add class="paleblue" to <table> tag
        attrs = {"class": "paleblue"}
        fields = ("selection", "id", "first_name", "last_name", "fullname", "region_name")

#class PersonTable(tables.Table):
#    class Meta:
#        model = Person
#        add class="paleblue" to <table> tag
#        attrs = {"class": "paleblue"}